package com.damocode.starter.yx.autoconfigure;

import com.damocode.starter.httpclient.autoconfigure.HttpClientAutoConfiguration;
import com.damocode.starter.httpclient.helper.HttpClientHelper;
import com.damocode.starter.yx.service.IIMMsgService;
import com.damocode.starter.yx.service.IIMUserService;
import com.damocode.starter.yx.service.impl.IMMsgService;
import com.damocode.starter.yx.service.impl.IMUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.Resource;

@Slf4j
@Configuration
@ConditionalOnClass({IMMsgService.class,IMUserService.class})
@EnableConfigurationProperties(IMProperties.class)
@AutoConfigureAfter(HttpClientAutoConfiguration.class)
public class IMAutoConfiguration {

    @Resource
    private IMProperties imProperties;

    @Resource
    private HttpClientHelper httpClientHelper;

    @Bean
    @ConditionalOnMissingBean(IMUserService.class)
    public IIMUserService imUserService(){
        return new IMUserService(imProperties,httpClientHelper);
    }

    @Bean
    @ConditionalOnMissingBean(IMMsgService.class)
    public IIMMsgService imMsgService(){
        return new IMMsgService(imProperties,httpClientHelper);
    }

}
